package org.zhouhe.web.util;

import java.sql.Timestamp;

import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;
public class ResponseUtils {
	
	private static JsonConfig jsonConfig;
	
	static{
		jsonConfig = new JsonConfig();
		jsonConfig.registerJsonValueProcessor(java.util.Date.class, new DateJsonValueProcessor());
		jsonConfig.registerJsonValueProcessor(java.sql.Date.class, new DateJsonValueProcessor());
		jsonConfig.registerJsonValueProcessor(Timestamp.class, new DateJsonValueProcessor());
	}
	
	public static void renderJson(Object obj, HttpServletResponse response){
		try {
			JSONObject jsonObj = JSONObject.fromObject(obj, jsonConfig);
			response.getWriter().print(jsonObj.toString());
			response.getWriter().flush();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
